# @Time : 2023/1/6
# @Author : SDAJAVA
import urllib.request
import json
import jsonpath

url = 'https://dianying.taobao.com/cityAction.json?activityId&_ksTS=1672987819096_168&jsoncallback=jsonp169&action=cityAction&n_s=new&event_submit_doGetAllRegion=true'

# 'accept-encoding': ' gzip, deflate, br',这个一定要删除,前边带:不要':method':' GET',
headers = {
    'accept': 'text/javascript, application/javascript, application/ecmascript, application/x-ecmascript, */*; q=0.01',
    'accept-language': 'zh-CN,zh;q=0.9',
    'bx-v': '2.2.3',
    'cookie': 'tracknick=%5Cu6709%5Cu6587%5Cu5316%5Cu7684%5Cu7C97%5Cu4EBAhsd; miid=599581134648894583; enc=pu0TSHfdOG0yWtLn77bfxPhqjrrA2zeNLmJ5%2FG2WdQgtA%2BRu9R7uS2hxEGs%2FKwbNOSFYT7%2FdqrByBQidq9es8g%3D%3D; useNativeIM=false; cna=YW3KG8nI7T0CASQspGJFzPSN; thw=cn; t=c6d140f1670465e6154b7e7eb6de9181; sgcookie=E100CdKq0Z6%2FeJdJb3FuTUOKVsp1hn%2Fta8QLP1bQiWbiYsCvyGRAC3w3tGzT4RsKDWmVhHpbIi%2Ftutpy5TK1Cbofp9QLhGd5jhMPL9CagB6IanQ%3D; uc3=vt3=F8dCvjETFfRvSpBsclc%3D&lg2=W5iHLLyFOGW7aA%3D%3D&nk2=sFDfApsFFXxl%2FrL0DA36&id2=UUkNYaaA%2BVmnzw%3D%3D; lgc=%5Cu6709%5Cu6587%5Cu5316%5Cu7684%5Cu7C97%5Cu4EBAhsd; uc4=nk4=0%40sqhuER0nB7tuyycOnL6%2FGsBva%2Bk%2BDYNB2xU%3D&id4=0%40U2uBaj%2BrmNCJ7doA4DkjyPGDlXr1; _cc_=URm48syIZQ%3D%3D; mt=ci=22_1; cookie2=267dcc731166c26ee1b9131819a62e2c; v=0; _tb_token_=eb345334e73ea; xlly_s=1; isg=BK-vcUQ9EJFJcyj72EpCk0WFPsO5VAN2g4lO58E8F54lEM8SySYNxufOkgAuMNvu; l=fBg4iij4O9wME_paBOfZnurza77OLIRYMuPzaNbMi9fP9eCH5lPfW67uo08MCnGVFsRwR3r0glSeBeYBqh4sjqj4axom4yDmnmOk-Wf..; tfstk=cipVBO9P4xH4FjKtJTXwaQy-VO5Aa9xDj8SCiVrzcJunAWfP8sV7Wgm4GgS_4Pfc.',
    'referer': 'https://dianying.taobao.com/',
    'sec-ch-ua': '"Google Chrome";v="107", "Chromium";v="107", "Not=A?Brand";v="24"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"',
    'sec-fetch-dest': 'empty',
    'sec-fetch-mode': 'cors',
    'sec-fetch-site': 'same-origin',
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36',
    'x-requested-with': 'XMLHttpRequest',
}

request = urllib.request.Request(url=url, headers=headers)
response = urllib.request.urlopen(request)
content = response.read().decode("utf-8")
# print(content)

content = content.split('(')[1].split(')')[0]

with open('tpp_city.json', 'w', encoding="utf-8") as fp:
    fp.write(content)

obj = json.load(open('tpp_city.json', 'r', encoding='utf-8'))
city_list = jsonpath.jsonpath(obj, '$..regionName')
print(city_list)
